#include <linux/module.h>
#include <linux/slab.h>
#include <linux/rhashtable.h>
#include "rwfile.h"
#include "utils.h"

#define MAX_ENTRY 64

// #define writeBoth(lbn, str) memset(buf, 0, BLKSZ);strcpy(buf, str);bWriteSimple(lbn, buf);write_dedup(lbn, buf);
// #define readBoth(lbn) bReadSimple(lbn, buf1);read_dedup(lbn, buf2);
// if(memcmp(buf1, buf2, BLKSZ)!=0){pr_alert("test failed"); pr_alert("lbn: %lu, buf1: %s, buf2: %s", (unsigned long)lbn, buf1, buf2);goto rderr;}

struct metadata_entry
{
    uint32_t fp;
    uint32_t pbn;
    uint32_t ref;
};

struct LBN2PBN
{
	struct rhash_head node;
	uint32_t lbn; // key
	uint32_t entry_id; // value
};

const struct rhashtable_params l2p_params = {
    .key_len = sizeof(uint32_t),
    .key_offset = offsetof(struct LBN2PBN, lbn),
    .head_offset = offsetof(struct LBN2PBN, node),
    .automatic_shrinking = true,
};

struct fp2PBN {
	struct rhash_head node;
	uint32_t fp; // key
	uint32_t entry_id; // value
};

const struct rhashtable_params f2p_params = {
    .key_len = sizeof(uint32_t),
    .key_offset = offsetof(struct fp2PBN, fp),
    .head_offset = offsetof(struct fp2PBN, node),
    .automatic_shrinking = true,
};

struct rhashtable l2p_rht, f2p_rht;
struct metadata_entry *entries;
uint32_t entry_cnt;
